﻿using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Utility;
using Model;
using Model.LinqModel;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class UserLoginDAL
    {
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public TPersonInfo Login(string UserName, string pwd)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(SqlHelper.AttemperConnectionString))
                {
                    DataBase db = new DataBase(con);
                    TPersonInfo user = (from tp in db.TPersonInfo
                                        where tp.GongHao == UserName && tp.KouLing == pwd && tp.ShiFouYouXiao == true
                                        select tp).FirstOrDefault();
                    if (user == null)
                    {
                        return null;
                    }
                    else
                    {
                        //获取人员归属分站对应的中心编码
                        user.ZhongXinBianMa = (from tp in db.TStationInfo
                                            where tp.BianMa == user.FenZhanBianMa
                                            select tp).FirstOrDefault().ZhongXinBianMa;
                        return user;
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("UserLoginDAL/Login", ex.Message);
                return null;
            }
        }
    }
}
